#pragma once

#include <cassert>

template <class T>
class Singleton
{
public:
	Singleton()
	{
		assert(!m_singleton);
		int offset = (int)(T*)1 - (int)(Singleton<T>*)(T*)1;
		m_singleton = (T*)((int)this + offset);
	};
	virtual ~Singleton()
	{
		assert(m_singleton);
		m_singleton = 0;
	};
	static T& getSingleton()
	{
		assert(m_singleton);
		return *m_singleton;
	};
	static T* getSingletonPtr()
	{
		assert(m_singleton);
		return m_singleton;
	};
	static bool isValid()
	{
		return m_singleton !=0;
	};
private:
	static T* m_singleton;
};

template<class T> T* Singleton<T>::m_singleton = 0;